/**
 * 
 */
package gml.android.listviews;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

/**
 * @author guilherme
 *
 */
public class OrderSeekBarAdapter extends ArrayAdapter<OrderSeekBar> {
	
	private ArrayList<OrderSeekBar> items;

	public OrderSeekBarAdapter(Context context, int textViewResourceId, ArrayList<OrderSeekBar> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)  getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.simple_fader_layout, null);
            }
            
            //now get the element at desired position
            final OrderSeekBar o = items.get(position);
            
            if (o != null) {
                    final TextView tt = (TextView) v.findViewById(R.id.textView);
                    SeekBar sb = (SeekBar) v.findViewById(R.id.seekBar);
                    
                    if (tt!=null) {
                          tt.setText(o.getOrderName());                            
                    }
                    if(sb!=null){
                    	sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
							
							@Override
							public void onStopTrackingTouch(SeekBar seekBar) {
								Log.d(seekBar.toString(), "stopped track");
								
							}
							
							@Override
							public void onStartTrackingTouch(SeekBar seekBar) {
								Log.d(seekBar.toString(), "start track");
								
							}
							
							@Override
							public void onProgressChanged(SeekBar seekBar, int progress,
									boolean fromUser) {
								Log.d(seekBar.toString(), "	value: "+progress);
								tt.setText(o.getOrderName()+": "+progress);
								
							}
						});
                    }
            }
            
            return v;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "["+items.toString()+"]";
	}
	
	

}
